<?php 
include("common.php");
if(isset($_POST['submit'])){
	$book_id = $_POST['book_id'];
    $book_name = $_POST['book_name'];
	$price = $_POST['price'];
	$author = $_POST['author'];
	$Press = $_POST['Press'];
	$addate = $_POST['addate'];
	$sql = "insert into book (book_id, book_name, price, author, Press, addate) values ('$book_id','$book_name','$price','$author','$Press','$addate')";
	$result = mysql_query($sql);
	$rows=mysql_affected_rows();
	if($rows<1){
		echo "<script>alert('添加失败！');window.location.href='book.php';</script>";
	}else{
		echo "<script>alert('添加成功！');window.location.href='book.php';</script>";
	}

}

?>
<html>
<head>
<script type="text/javascript">
function checkForm(form) {
if(form.book_id.value == "") {
alert("图书编号不能为空!");
form.book_id.focus();
return false;
}
if(form.book_name.value == "") {
alert("图书名称不能为空!");
form.book_name.focus();
return false;
}
if(form.price.value == "") {
alert("价格不能为空!");
form.price.focus();
return false;
}
if(form.author.value == "") {
alert("作者不能为空!");
form.author.focus();
return false;
}
if(form.Press.value == "") {
alert("出版社不能为空!");
form.Press.focus();
return false;
}
return true;
}
</script>
</head>
<body>
 <div class="fr righter">
		  <div class="title">
		  <h1 align="center"> 添加图书信息</h1>
	      </div>
		  
		  <table class="bd" width="600" align="center">
		  <form action="#" method="post" onSubmit="return checkForm(this);">
          		      <tr>
				  <td align="center" height="30">图书编号:</td>
			    <td align="center"><input type="text" name="book_id" /></td>
			  </tr>
		      <tr>
				  <td align="center" height="30">图书名称:</td>
			    <td align="center"><input type="text" name="book_name" /></td>
			  </tr>
			  <tr>
				  <td align="center" height="30">图书价格:</td>
			    <td align="center"><input type="text" name="price" /></td>
			  </tr>
			  <tr>
				  <td align="center" height="30">作者:</td>
			    <td align="center"><input type="text" name="author" /></td>
			  </tr>
			  <tr>
				  <td align="center" height="30">出版社:</td>
			    <td align="center"><input type="text" name="Press" /></td>
			  </tr>
			   <tr>
				  <td align="center" height="30">出版时间:</td>
			     <td align="center"><input type="text" name="addate" value="2020-06-28" /></td>
			  </tr>
  		
			  <tr>
				  <td colspan=2 align="center" height="30"><input type="submit" name="submit" value="添加"/></td>
			  </tr>
		  </form>
	   </table>

	  </div>
  </div>
  
 </body>
</html>
 

